package com.lyf.baoxian.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lyf.baoxian.R;
import com.lyf.baoxian.adapter.AddressAdapter;
import com.lyf.baoxian.bean.MyCity;
import com.lyf.baoxian.utils.MyMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 刘亚飞 on 2017/2/9.
 */

public class SelectAdsActivity extends Activity {
    private List<String> datas;
    private ListView lv_ads;
    private AddressAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_address);
        initData();
        initView();
    }

    /**
     * 初始化布局
     */
    private void initView() {
        lv_ads = (ListView) findViewById(R.id.lv_ads);
        adapter = new AddressAdapter(this);
        adapter.setDatas(datas);
        lv_ads.setAdapter(adapter);
        lv_ads.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String city= datas.get(i);
                Intent intent = new Intent();
                intent.putExtra("city",city);
                setResult(1001,intent);
                finish();
            }
        });

    }

    /**
     * 初始化数据
     */
    private void initData() {
        MyMethod.setTitle(this, "选择地址");
        datas = new ArrayList<>();
        datas.add("北京");
        datas.add("上海");
        datas.add("南京");
        datas.add("广州");
        datas.add("深圳");
        datas.add("杭州");
        datas.add("江苏");
        datas.add("河北");
        datas.add("哈尔滨");
    }
}
